﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EnvironmentManagerSystem.MODE;
using EnvironmentManagerSystem.BLL;
using System.Data;

namespace EnvironmentManagerSystem.ExpertManager
{
    public partial class AddExpert : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (StfInfo.ReSession()) return;if (!IsPostBack)
            {
                BingData();
            }
        }

        public void BingData()
        {
            // 绑定专家类型下拉菜单
            ExpertKindDataList ekl = ExpertKind.GetList();
            if(ekl!=null)
            {
                foreach(ExpertKindData model in ekl )
                {
                    txtExpertType.Items.Add(model.ExpertKindCode.Trim()+model.ExpertKindName.Trim());
                }
            }
            //绑定行业领域
            ExpertIndustryKindOneDataList eikodl = ExpertIndustryKindOne.GetList();
            if (eikodl!=null)
            {
                foreach (ExpertIndustryKindOneData model in eikodl)
                {
                    lbUnchoose.Items.Add(model.ExpertIndustryKindOneCode.Trim()+model.ExpertIndustryKindOneName.Trim());
                }
            }
            //绑定评估类别
            ExpertIndustryKindTwoDataList lst2 = ExpertIndustryKindTwo.GetList();

            if (lst2 != null)
            {
                foreach (ExpertIndustryKindTwoData model in lst2)
                {
                    lbUnChoose1.Items.Add(model.ExpertIndustryKindTwoCode.Trim() + model.ExpertIndustryKindTwoName.Trim());
                }
            }

        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            ExpertData model = new ExpertData();
            model.Name = txtExpertName.Text.Trim();
            model.Birthday = txtBirthday.Text.Trim();
            //组建行业类别
            string BusinessType="";
            for (int i = 0; i < lbChoose.Items.Count;i++ )
            {
                BusinessType = BusinessType + lbChoose.Items[i]+",";
            }
            model.BusinessType = BusinessType.Trim();
            model.CardNo = txtCertNo.Text.Trim();
            string EIAType="";
            for (int i = 0; i < lbChoose1.Items.Count;i++ )
            {
                EIAType = EIAType + lbChoose1.Items[i]+",";
            }
            model.EIAType = EIAType.Trim();
            model.Email = txtEMail.Text.Trim();
            model.ExpertMemo = TextBox1.Text.Trim();
            model.ExpertType = txtExpertType.SelectedValue;
            model.Fax = txtFax.Text.Trim();
            model.Mobile = txtMobile.Text.Trim();
            model.NowWork = txtNowCompany.Text.Trim();
            model.Phone = txtPhone.Text.Trim();
            model.Recommendation = txtRecommendation.Text.Trim();
            model.Sex = txtSex.Text.Trim();
            model.Title = txtTitle.Text.Trim();
            model.Work = txtCompany.Text.Trim();
            if (Expert.Add(model) > 0)
            {
                Response.Write("<script>alert('添加成功');window.parent.art.dialog.list['新增专家'].close();</script>");
            }
            else
            {
                Jscript.Alert("添加失败!", this);
            }
        }

        protected void btnChoose_Click(object sender, EventArgs e)
        {
            if (lbUnchoose.SelectedValue != "")
            {
                lbChoose.Items.Add(lbUnchoose.SelectedValue);
                lbUnchoose.Items.RemoveAt(lbUnchoose.SelectedIndex);
            }
        }

        protected void btnUnChoose_Click(object sender, EventArgs e)
        {
            if (lbChoose.SelectedValue != "")
            {
                lbUnchoose.Items.Add(lbChoose.SelectedValue);
                lbChoose.Items.RemoveAt(lbChoose.SelectedIndex);
            }
        }

        protected void btnChoose1_Click(object sender, EventArgs e)
        {
            if (lbUnChoose1.SelectedValue != "")
            {
                lbChoose1.Items.Add(lbUnChoose1.SelectedValue);
                lbUnChoose1.Items.RemoveAt(lbUnChoose1.SelectedIndex);
            }
        }

        protected void btnUnChoose1_Click(object sender, EventArgs e)
        {
            if (lbChoose1.SelectedValue != "")
            {
                lbUnChoose1.Items.Add(lbChoose1.SelectedValue);
                lbChoose1.Items.RemoveAt(lbChoose1.SelectedIndex);
            }
        }

        protected void btncancel_Click(object sender, EventArgs e)
        {
            Response.Write("<script>window.parent.art.dialog.list['新增专家'].close();</script>");
        }
    }
}
